--******************************************************************
-- Circo.Framework.Generated
-- Fecha:5/16/2009 7:25 PM
--
-- TABLES
--******************************************************************


--******************************************************************
-- Entity: [ActividadEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Actividad]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Actividad]
GO

CREATE TABLE [dbo].[Actividad]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Actividad] PRIMARY KEY CLUSTERED,
   [IdBoda] INT NOT NULL,
   [IdTipoProd] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Actividad] ON [Actividad]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [BodaEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Boda]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Boda]
GO

CREATE TABLE [dbo].[Boda]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Boda] PRIMARY KEY CLUSTERED,
   [Fecha] DATETIME NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Boda] ON [Boda]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [CaracteristicaEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Caracteristica]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Caracteristica]
GO

CREATE TABLE [dbo].[Caracteristica]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Caracteristica] PRIMARY KEY CLUSTERED,
   [Nombre] VARCHAR(50) NOT NULL,
   [Detalle] VARCHAR(100) NOT NULL,
   [IdProdSer] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Caracteristica] ON [Caracteristica]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ComentarioEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Comentario]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Comentario]
GO

CREATE TABLE [dbo].[Comentario]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Comentario] PRIMARY KEY CLUSTERED,
   [IdUsuario] INT NOT NULL,
   [IdProdSer] INT NOT NULL,
   [Comentario] VARCHAR(500) NOT NULL,
   [Calificacion] SMALLINT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Comentario] ON [Comentario]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ConsultaEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Consulta]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Consulta]
GO

CREATE TABLE [dbo].[Consulta]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Consulta] PRIMARY KEY CLUSTERED,
   [IdUsuario] INT NOT NULL,
   [IdProdser] INT NOT NULL,
   [Consulta] VARCHAR(500) NOT NULL,
   [Respuesta] VARCHAR(500) NOT NULL,
   [Respondido] BIT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Consulta] ON [Consulta]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ContactoEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Contacto]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Contacto]
GO

CREATE TABLE [dbo].[Contacto]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Contacto] PRIMARY KEY CLUSTERED,
   [IdUsuario] INT NOT NULL,
   [IdAmigo] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Contacto] ON [Contacto]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ContratacionEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Contratacion]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Contratacion]
GO

CREATE TABLE [dbo].[Contratacion]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Contratacion] PRIMARY KEY CLUSTERED,
   [IdBoda] INT NOT NULL,
   [IdProdSer] INT NOT NULL,
   [Precio] DECIMAL(8,2) NOT NULL,
   [ConfirmBoda] BIT NOT NULL,
   [ConfirmEmpresa] BIT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Contratacion] ON [Contratacion]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [FotoBodaEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FotoBoda]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[FotoBoda]
GO

CREATE TABLE [dbo].[FotoBoda]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_FotoBoda] PRIMARY KEY CLUSTERED,
   [Imagen] VARBINARY(MAX) NOT NULL,
   [IdBoda] INT NOT NULL,
   [Nombre] VARCHAR(100) NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_FotoBoda] ON [FotoBoda]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [FotoEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Foto]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Foto]
GO

CREATE TABLE [dbo].[Foto]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Foto] PRIMARY KEY CLUSTERED,
   [Nombre] VARCHAR(50) NOT NULL,
   [Descripcion] VARCHAR(250) NOT NULL,
   [IdProdSer] INT NOT NULL,
   [Imagen] VARBINARY(MAX) NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Foto] ON [Foto]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [InvitadoEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Invitado]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Invitado]
GO

CREATE TABLE [dbo].[Invitado]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Invitado] PRIMARY KEY CLUSTERED,
   [Nombre] VARCHAR(50) NOT NULL,
   [Mail] VARCHAR(100) NOT NULL,
   [IdBoda] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Invitado] ON [Invitado]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [LocalidadEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Localidad]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Localidad]
GO

CREATE TABLE [dbo].[Localidad]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Localidad] PRIMARY KEY CLUSTERED,
   [IdProvincia] INT NOT NULL,
   [Nombre] VARCHAR(50) NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Localidad] ON [Localidad]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ProdSerEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProdSer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ProdSer]
GO

CREATE TABLE [dbo].[ProdSer]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_ProdSer] PRIMARY KEY CLUSTERED,
   [IdTipo] INT NOT NULL,
   [Precio] DECIMAL(10,2) NOT NULL,
   [Categoria] SMALLINT NOT NULL,
   [Descripcion] VARCHAR(250) NOT NULL,
   [IdProveedor] INT NOT NULL,
   [Denominacion] VARCHAR(100) NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_ProdSer] ON [ProdSer]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ProdSerLocEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ProdSerLoc]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ProdSerLoc]
GO

CREATE TABLE [dbo].[ProdSerLoc]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_ProdSerLoc] PRIMARY KEY CLUSTERED,
   [IdProdSer] INT NOT NULL,
   [IdLocalidad] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_ProdSerLoc] ON [ProdSerLoc]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ProveedorEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Proveedor]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Proveedor]
GO

CREATE TABLE [dbo].[Proveedor]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Proveedor] PRIMARY KEY CLUSTERED,
   [Nombre] VARCHAR(50) NULL,
   [IdProvincia] INT NOT NULL,
   [Direccion] VARCHAR(250) NULL,
   [IdLocalidad] INT NOT NULL,
   [Telefono] VARCHAR(50) NULL,
   [Mail] VARCHAR(100) NOT NULL,
   [NombreUsuario] VARCHAR(50) NOT NULL,
   [Contrasenia] VARCHAR(50) NOT NULL,
   [NombreResp] VARCHAR(50) NOT NULL,
   [ApellidoResp] VARCHAR(50) NOT NULL,
   [DNIResp] VARCHAR(15) NOT NULL,
   [Activo] BIT NOT NULL,
   [TipoDNI] SMALLINT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Proveedor] ON [Proveedor]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [ProvinciaEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Provincia]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Provincia]
GO

CREATE TABLE [dbo].[Provincia]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Provincia] PRIMARY KEY CLUSTERED,
   [Nombre] VARCHAR(50) NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Provincia] ON [Provincia]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [SolicitudDeTipoEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[SolicitudDeTipo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[SolicitudDeTipo]
GO

CREATE TABLE [dbo].[SolicitudDeTipo]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_SolicitudDeTipo] PRIMARY KEY CLUSTERED,
   [NombrePropuesto] VARCHAR(50) NOT NULL,
   [Razon] VARCHAR(250) NOT NULL,
   [CategPropuesta] SMALLINT NOT NULL,
   [IdProveedor] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_SolicitudDeTipo] ON [SolicitudDeTipo]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [TipoProdEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TipoProd]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TipoProd]
GO

CREATE TABLE [dbo].[TipoProd]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_TipoProd] PRIMARY KEY CLUSTERED,
   [Tipo] VARCHAR(50) NOT NULL,
   [Categoria] SMALLINT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_TipoProd] ON [TipoProd]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [UsuarioBodaEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UsuarioBoda]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UsuarioBoda]
GO

CREATE TABLE [dbo].[UsuarioBoda]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_UsuarioBoda] PRIMARY KEY CLUSTERED,
   [IdUsuario] INT NOT NULL,
   [IdBoda] INT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_UsuarioBoda] ON [UsuarioBoda]([Id]) ON [PRIMARY] 

GO


--******************************************************************
-- Entity: [UsuarioEntity]
--******************************************************************

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Usuario]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Usuario]
GO

CREATE TABLE [dbo].[Usuario]
(
   [Id] INT IDENTITY(1, 1) NOT NULL CONSTRAINT [PK_Usuario] PRIMARY KEY CLUSTERED,
   [Nombre] VARCHAR(50) NOT NULL,
   [Apellido] VARCHAR(50) NOT NULL,
   [NombreUsuario] VARCHAR(50) NOT NULL,
   [Contrasenia] VARCHAR(50) NOT NULL,
   [Mail] VARCHAR(100) NOT NULL,
   [DNI] VARCHAR(15) NOT NULL,
   [Direccion] VARCHAR(50) NOT NULL,
   [IdProvincia] INT NOT NULL,
   [IdLocalidad] INT NOT NULL,
   [TipoDNI] SMALLINT NOT NULL,
   [Sexo] SMALLINT NOT NULL
)
ON [PRIMARY]

GO

CREATE INDEX [IDX_Usuario] ON [Usuario]([Id]) ON [PRIMARY] 

GO


ALTER TABLE [Actividad]
ADD CONSTRAINT [FK_Boda_Actividad_IdBoda] FOREIGN KEY (IdBoda)
REFERENCES [Boda] ([Id])
ALTER TABLE [Actividad]
ADD CONSTRAINT [FK_TipoProd_Actividad_IdTipoProd] FOREIGN KEY (IdTipoProd)
REFERENCES [TipoProd] ([Id])
ALTER TABLE [Caracteristica]
ADD CONSTRAINT [FK_ProdSer_Caracteristica_IdProdSer] FOREIGN KEY (IdProdSer)
REFERENCES [ProdSer] ([Id])
ALTER TABLE [Comentario]
ADD CONSTRAINT [FK_Usuario_Comentario_IdUsuario] FOREIGN KEY (IdUsuario)
REFERENCES [Usuario] ([Id])
ALTER TABLE [Comentario]
ADD CONSTRAINT [FK_ProdSer_Comentario_IdProdSer] FOREIGN KEY (IdProdSer)
REFERENCES [ProdSer] ([Id])
ALTER TABLE [Consulta]
ADD CONSTRAINT [FK_Usuario_Consulta_IdUsuario] FOREIGN KEY (IdUsuario)
REFERENCES [Usuario] ([Id])
ALTER TABLE [Consulta]
ADD CONSTRAINT [FK_ProdSer_Consulta_IdProdser] FOREIGN KEY (IdProdser)
REFERENCES [ProdSer] ([Id])
ALTER TABLE [Contacto]
ADD CONSTRAINT [FK_Usuario_Contacto_IdUsuario] FOREIGN KEY (IdUsuario)
REFERENCES [Usuario] ([Id])
ALTER TABLE [Contacto]
ADD CONSTRAINT [FK_Usuario_Contacto_IdAmigo] FOREIGN KEY (IdAmigo)
REFERENCES [Usuario] ([Id])
ALTER TABLE [Contratacion]
ADD CONSTRAINT [FK_Boda_Contratacion_IdBoda] FOREIGN KEY (IdBoda)
REFERENCES [Boda] ([Id])
ALTER TABLE [Contratacion]
ADD CONSTRAINT [FK_ProdSer_Contratacion_IdProdSer] FOREIGN KEY (IdProdSer)
REFERENCES [ProdSer] ([Id])
ALTER TABLE [FotoBoda]
ADD CONSTRAINT [FK_Boda_FotoBoda_IdBoda] FOREIGN KEY (IdBoda)
REFERENCES [Boda] ([Id])
ALTER TABLE [Foto]
ADD CONSTRAINT [FK_ProdSer_Foto_IdProdSer] FOREIGN KEY (IdProdSer)
REFERENCES [ProdSer] ([Id])
ALTER TABLE [Invitado]
ADD CONSTRAINT [FK_Boda_Invitado_IdBoda] FOREIGN KEY (IdBoda)
REFERENCES [Boda] ([Id])
ALTER TABLE [Localidad]
ADD CONSTRAINT [FK_Provincia_Localidad_IdProvincia] FOREIGN KEY (IdProvincia)
REFERENCES [Provincia] ([Id])
ALTER TABLE [ProdSer]
ADD CONSTRAINT [FK_TipoProd_ProdSer_IdTipo] FOREIGN KEY (IdTipo)
REFERENCES [TipoProd] ([Id])
ALTER TABLE [ProdSer]
ADD CONSTRAINT [FK_Proveedor_ProdSer_IdProveedor] FOREIGN KEY (IdProveedor)
REFERENCES [Proveedor] ([Id])
ALTER TABLE [ProdSerLoc]
ADD CONSTRAINT [FK_ProdSer_ProdSerLoc_IdProdSer] FOREIGN KEY (IdProdSer)
REFERENCES [ProdSer] ([Id])
ALTER TABLE [ProdSerLoc]
ADD CONSTRAINT [FK_Localidad_ProdSerLoc_IdLocalidad] FOREIGN KEY (IdLocalidad)
REFERENCES [Localidad] ([Id])
ALTER TABLE [Proveedor]
ADD CONSTRAINT [FK_Provincia_Proveedor_IdProvincia] FOREIGN KEY (IdProvincia)
REFERENCES [Provincia] ([Id])
ALTER TABLE [Proveedor]
ADD CONSTRAINT [FK_Localidad_Proveedor_IdLocalidad] FOREIGN KEY (IdLocalidad)
REFERENCES [Localidad] ([Id])
ALTER TABLE [SolicitudDeTipo]
ADD CONSTRAINT [FK_Proveedor_SolicitudDeTipo_IdProveedor] FOREIGN KEY (IdProveedor)
REFERENCES [Proveedor] ([Id])
ALTER TABLE [UsuarioBoda]
ADD CONSTRAINT [FK_Usuario_UsuarioBoda_IdUsuario] FOREIGN KEY (IdUsuario)
REFERENCES [Usuario] ([Id])
ALTER TABLE [UsuarioBoda]
ADD CONSTRAINT [FK_Boda_UsuarioBoda_IdBoda] FOREIGN KEY (IdBoda)
REFERENCES [Boda] ([Id])
ALTER TABLE [Usuario]
ADD CONSTRAINT [FK_Provincia_Usuario_IdProvincia] FOREIGN KEY (IdProvincia)
REFERENCES [Provincia] ([Id])
ALTER TABLE [Usuario]
ADD CONSTRAINT [FK_Localidad_Usuario_IdLocalidad] FOREIGN KEY (IdLocalidad)
REFERENCES [Localidad] ([Id])
